package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarInspection;
import com.ruoyi.car.service.ICarInspectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年检Controller
 * 
 * @author ruoyi
 * @date 2022-12-03
 */
@RestController
@RequestMapping("/car/inspection")
public class CarInspectionController extends BaseController
{
    @Autowired
    private ICarInspectionService carInspectionService;

    /**
     * 查询年检列表
     */
    @PreAuthorize("@ss.hasPermi('car:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarInspection carInspection)
    {
        startPage();
        List<CarInspection> list = carInspectionService.selectCarInspectionList(carInspection);
        return getDataTable(list);
    }

    /**
     * 导出年检列表
     */
    @PreAuthorize("@ss.hasPermi('car:inspection:export')")
    @Log(title = "年检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarInspection carInspection)
    {
        List<CarInspection> list = carInspectionService.selectCarInspectionList(carInspection);
        ExcelUtil<CarInspection> util = new ExcelUtil<CarInspection>(CarInspection.class);
        util.exportExcel(response, list, "年检数据");
    }

    /**
     * 获取年检详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:inspection:query')")
    @GetMapping(value = "/{inspectionId}")
    public AjaxResult getInfo(@PathVariable("inspectionId") Long inspectionId)
    {
        return success(carInspectionService.selectCarInspectionByInspectionId(inspectionId));
    }

    /**
     * 新增年检
     */
    @PreAuthorize("@ss.hasPermi('car:inspection:add')")
    @Log(title = "年检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarInspection carInspection)
    {
        return toAjax(carInspectionService.insertCarInspection(carInspection));
    }

    /**
     * 修改年检
     */
    @PreAuthorize("@ss.hasPermi('car:inspection:edit')")
    @Log(title = "年检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarInspection carInspection)
    {
        return toAjax(carInspectionService.updateCarInspection(carInspection));
    }

    /**
     * 删除年检
     */
    @PreAuthorize("@ss.hasPermi('car:inspection:remove')")
    @Log(title = "年检", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectionIds}")
    public AjaxResult remove(@PathVariable Long[] inspectionIds)
    {
        return toAjax(carInspectionService.deleteCarInspectionByInspectionIds(inspectionIds));
    }
}
